<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Random Number Generator &mdash; SIMULATeQCD 0.7 documentation</title>
      <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
      <link rel="stylesheet" href="../_static/togglebutton.css" type="text/css" />
      <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/togglebutton.js"></script>
        <script>var togglebuttonSelector = '.toggle, .admonition.dropdown';</script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="HISQ smearing" href="gaugeSmearing.html" />
    <link rel="prev" title="Integrator" href="integrator.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #343131" >
            <a href="../index.html" class="icon icon-home"> SIMULATeQCD
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../01_gettingStarted/gettingStarted.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../02_contributions/contributions.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../03_applications/applications.html">Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../04_codeBase/codeBase.html">Code base</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">Modules</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="inverter.html">Inverter (Conjugate Gradient)</a></li>
<li class="toctree-l2"><a class="reference internal" href="correlator.html">Correlator Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="gaugeUpdates.html">Gauge Updates (HB and OR)</a></li>
<li class="toctree-l2"><a class="reference internal" href="dslash.html">Dslash</a></li>
<li class="toctree-l2"><a class="reference internal" href="integrator.html">Integrator</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Random Number Generator</a></li>
<li class="toctree-l2"><a class="reference internal" href="gaugeSmearing.html">HISQ smearing</a></li>
</ul>
</li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu"  style="background: #343131" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">SIMULATeQCD</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
          <li><a href="modules.html">Modules</a> &raquo;</li>
      <li>Random Number Generator</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/05_modules/randomNumbers.md.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section class="tex2jax_ignore mathjax_ignore" id="random-number-generator">
<h1>Random Number Generator<a class="headerlink" href="#random-number-generator" title="Permalink to this headline"></a></h1>
<p>The random number generator is using using the hybrid Tausworthe generator from
<a class="reference external" href="https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch37.html">here</a>. The state of the random number
generator consists of four unsigned integers (We use the GPU type <code class="docutils literal notranslate"><span class="pre">uint4</span></code>) and every site of the
lattice has its own state. A random number, e.g. in a Kernel is generated with the function</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">floatT</span><span class="w"> </span><span class="n">get_rand</span><span class="p">(</span><span class="n">uint4</span><span class="o">*</span><span class="w"> </span><span class="n">state</span><span class="p">)</span><span class="w"></span>
</pre></div>
</div>
<p>The argument is a pointer on the <code class="docutils literal notranslate"><span class="pre">uint4</span></code> element on the given site, not on the whole uint4 array that runs over the lattice!
You now have two choices how to do this: 1) pass your kernel a reference of the rng state object and use the getElement function</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">uint4</span><span class="o">*</span><span class="w"> </span><span class="n">getElement</span><span class="p">(</span><span class="n">gSite</span><span class="w"> </span><span class="n">site</span><span class="p">)</span><span class="w"></span>
</pre></div>
</div>
<p>or 2) pass your kernel a reference of the <code class="docutils literal notranslate"><span class="pre">uint4</span></code> array state (it is a public member of the rng state class) and call</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">floatT</span><span class="w"> </span><span class="n">get_rand</span><span class="p">(</span><span class="o">&amp;</span><span class="n">state</span><span class="p">[</span><span class="n">site</span><span class="p">.</span><span class="n">isite</span><span class="p">])</span><span class="w"></span>
</pre></div>
</div>
<section id="generating-the-rng-state">
<h2>Generating the RNG State<a class="headerlink" href="#generating-the-rng-state" title="Permalink to this headline"></a></h2>
<p>Before drawing random numbers we have to generate the state of the random number generator from a seed. This seed is an unsigned integer that should be specified in the parameter file. The function to set up the
the rng state is</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="n">make_rng_state</span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">seed</span><span class="p">)</span><span class="w"></span>
</pre></div>
</div>
<p>It is rather slow, though that does not matter as we have to call it only at the beginning of a completely new run/measurement. It is so slow as it is backwards compatible to the old BielefeldGPU code.
The state is generated on the Host so remember to copy it to the device! You can use the <code class="docutils literal notranslate"><span class="pre">=</span></code> operator for that.</p>
</section>
</section>


           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2021, LatticeQCD.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>